<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:83:"C:\phpstudy\WWW\tea\public/../application/datamanage\view\zhenpin\show_zhenpin.html";i:1533900396;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>珍品评价</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="favicon.ico"> <link href="/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/static/css/animate.css" rel="stylesheet">
    <link href="/static/css/style.css?v=4.1.0" rel="stylesheet">
    <style type="text/css">
        th,td{
            text-align: center;
            width: 10%;
        }
        body{
            text-align: center;
        }
        input{
            text-align: center;
        }
    </style>
</head>
<body>
<h1>珍品评价</h1>
<form class="form-horizontal m-t" id="signupForm" action="<?php echo url('showZhenpin'); ?>" method="post" enctype="multipart/form-data">
    <div class="form-group" style="text-align: center; margin: 0 auto;">
        <label class="col-sm-1 control-label">茶类</label>
        <div class="col-sm-2">
            <select class="form-control m-b " name="teacase" style="font-size: 12px;">
                <option value="10000" <?php if($currentteacase==10000): ?>selected="selected" <?php endif; ?>>查看全部</option>
                <?php foreach($teacase as $case): ?>
                <option value="<?php echo $case['id']; ?>" <?php if($currentteacase==$case['id']): ?>selected="selected" <?php endif; ?>><?php echo $case['teaname']; ?></option>
                <?php endforeach; ?>
                <option value="9999" <?php if($currentteacase==9999): ?>selected="selected" <?php endif; ?>>其它</option>
            </select>
        </div>

        <label class="col-sm-1 control-label">产区</label>
        <div class="col-sm-2">
            <select class="form-control m-b" name="teaarea" style="font-size: 12px;">
                <option value="10000" <?php if($currentteaarea==10000): ?>selected="selected"<?php endif; ?>>查看全部</option>
                <?php if($areas): foreach($areas as $a): ?>
                <option value="<?php echo $a['id']; ?>" <?php if($a['id']==$currentteaarea): ?>selected="selected"<?php endif; ?>><?php echo $a['area']; ?></option>
                <?php endforeach; endif; ?>
                <option value="9999" <?php if($currentteaarea==9999): ?>selected="selected"<?php endif; ?>>其它</option>
            </select>
        </div>
        <div class="col-sm-2">
            <button class="btn btn-primary" type="submit">提交</button>
        </div>
    </div>
</form>

<?php if($data): ?>
<p>A++:95~99 &nbsp;&nbsp;&nbsp;A+:90~94分&nbsp;&nbsp;&nbsp; A:85~89&nbsp;&nbsp;&nbsp; A-:80~84&nbsp;&nbsp;&nbsp; B:低于80 </p>
<div class="ibox-content" style="width:80%;margin: 0 auto;">
    <table class="table table-bordered" >
        <thead>
            <tr>
                <th>排名</th>
                <th style="width: 15%;">真品名称</th>
                <th>茶类</th>
                <th>产地</th>
                <th>评价</th>
                <th>前端显示得分</th>
                <th>计算后得分</th>
                <th>手动设置分数</th>
                <th>修改</th>
                <th>上榜</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach($data as $d): ?>
            <tr index = '<?php echo $d['id']; ?>'>
                <td><?php echo $d['rank']; ?></td>
                <td style="width: 15%;"><?php echo $d['name']; ?></td>
                <td><?php echo $d['teacase']; ?></td>
                <td><?php echo $d['teaarea']; ?></td>
                <td>
                    <?php if($d['score'] < 80): ?> 寻常之物
                    <?php elseif($d['score'] < 85): ?>不可多得
                    <?php elseif($d['score'] < 90): ?>难得一见
                    <?php elseif($d['score'] < 95): ?>百里挑一
                    <?php else: ?> 登峰造极
                    <?php endif; ?>
                </td>
                <td index="<?php echo $d['id']; ?>">
                    <?php if($d['score'] < 80): ?> B
                    <?php elseif($d['score'] < 85): ?>A-
                    <?php elseif($d['score'] < 90): ?>A
                    <?php elseif($d['score'] < 95): ?>A+
                    <?php else: ?> A++
                    <?php endif; ?>
                </td>
                <td>
                    <?php echo $d['score']; ?>
                </td>
                <td><input type="text"></td>
                <td><button class="modify" index = "<?php echo $d['id']; ?>">修改</button></td>
                <?php if($d['bangdan_id']==3): ?>
                <td>
                    <button class="YoN" indexm="<?php echo $d['id']; ?>" value="4">是</button>
                </td>
                <?php else: ?>
                <td><button class="YoN" indexm="<?php echo $d['id']; ?>" value="3" style="color: red;">否</button></td>
                <?php endif; ?>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <form action="<?php echo url('updateAll'); ?>">
        <button " data-toggle="modal"  data-target="#delmod" style="display: none;">同步数据</button>
    </form>
    <div style="color: red;display: none;">同步数据将会把前端显示的得分全部变更会计算后得分，手动修改的分数将会清0</div>
</div>
<?php endif; ?>



<!-- 全局js -->
<script src="/static/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/js/bootstrap.min.js?v=3.3.6"></script>

<script type="text/javascript">
    $(".modify").click(function(){
        var url = "<?php echo url('modify'); ?>";
        var id = $(this).attr("index");
        var score = $(this).parents("tr").find("input").val();
        if(isNaN(score)){
            alert("您输入的不是数字")
            $(this).parents("tr").find("input").val('');
            exit();
        }
        if(score>=100){
            score =99;
        }
        var data = {
            id:id,
            score:score
        };
        $.post(url,data,function(data){
            $("td[index="+id+"]").html(data);
            alert("修改成功");
        })
    })

    $("select[name=teacase] ").change(function(){
        var val = $(this).find("option:selected").attr("value");
        if(val == 10000){
            var inner = "<option value="+10000+">查看全部</option>";
            $("select[name=teaarea]").html(inner);
            exit();
        }
        if(val == 9999){
            var a = "<option value="+9999+">其它</option>";
            $("select[name=teaarea]").html(a);
            exit();
        }

        var url="<?php echo url('reTeaAreaJson'); ?>";
        $.post(url, {teacase_id:val},function(data){
            var areas = JSON.parse(data);
            var option="<option value='10000'>查看全部</option>";
            for(index in areas){
                var a = "<option value="+areas[index]['id']+">"+areas[index]['area']+"</option>"
                option +=a;
            }
            option += "<option value='9999'>其它</option>";
            $("select[name=teaarea]").html(option)
        })
    })


    $('.YoN').click(function(){
        var url = "<?php echo url('entries/Zhenpin/shangbang'); ?>";
        var a = $(this).html();
        var id = $(this).attr("indexm");
        var bangdan_id = $(this).attr("value");
        var data = {
            id:id,
            bangdan_id:bangdan_id
        }
        $.post(url,data,function(data){
            if(data == 1){
                if(a=="是"){
                    $('button[indexm='+id+']').html("否");
                    $('button[indexm='+id+']').attr('value',2);
                    $('button[indexm='+id+']').attr('style',"color: red;");
                }else{
                    $('button[indexm='+id+']').html("是");
                    $('button[indexm='+id+']').attr('value',4);
                    $('button[indexm='+id+']').attr('style',"color: none;");
                }
                alert('修改成功');
            }else{
                alert('修改失败');
            }
        })
   })

</script>
</body>
</html>